package com.itheima.edu.info.manager.service;

import com.itheima.edu.info.manager.dao.StudentDao;
import com.itheima.edu.info.manager.domain.Student;

public class StudentService {

    public static boolean isExists(String id) {
        Student[] stus = StudentDao.findAllStudent();
        //假设ID在数组中不存在
        boolean exists = false;
        for (int i = 0; i < stus.length; i++) {
            Student student = stus[i];
            if(student != null && student.getId().equals(id)){
                exists = true;
                break;
            }
        }
        return exists;
    }

    public static Student[] findAllStudent() {
        Student[] allStudent = StudentDao.findAllStudent();

        boolean flag = false;
        for (int i = 0; i < allStudent.length; i++) {
            Student stu = allStudent[i];
            if(stu != null){
                flag = true;
                break;
            }
        }

        if(flag){
            //有信息
            return allStudent;
        }else{
            //没信息
            return null;
        }
    }

    public static void deleteStudentById(String delId) {

        StudentDao.deleteStudentById(delId);
    }

    public static void updateStudent(String updateId, Student newStu) {

        StudentDao.updateStudent(updateId,newStu);
    }

    public boolean addStudent(Student stu) {
        StudentDao studentDao = new StudentDao();
        return StudentDao.addStudent(stu);
    }
}
